﻿using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace RegPort
{
    class RegistryMonitor: IDisposable
	{
		/// <summary>
		/// The NotifyIcon object.
		/// </summary>
		NotifyIcon m_notify;

		/// <summary>
		/// Initializes a new instance of the <see cref="ProcessIcon"/> class.
		/// </summary>
        public RegistryMonitor()
		{
			// Instantiate the NotifyIcon object.
            m_notify = new NotifyIcon();
		}

		/// <summary>
		/// Displays the icon in the system tray.
		/// </summary>
		public void Display()
		{
			// Put the icon in the system tray and allow it react to mouse clicks.			
            m_notify.MouseClick += new MouseEventHandler(ni_MouseClick);
            //m_notify.Icon = Resources.SystemTrayApp;
            m_notify.Text = "System Tray Utility Application Demonstration Program";
            m_notify.Visible = true;

			// Attach a context menu.
            //m_notify.ContextMenuStrip = new ContextMenus().Create();
		}

		/// <summary>
		/// Releases unmanaged and - optionally - managed resources
		/// </summary>
		public void Dispose()
		{
			// When the application closes, this will remove the icon from the system tray immediately.
            m_notify.Dispose();
		}

		/// <summary>
		/// Handles the MouseClick event of the ni control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
		void ni_MouseClick(object sender, MouseEventArgs e)
		{
			// Handle mouse button clicks.
			if (e.Button == MouseButtons.Left)
			{
				// Start Windows Explorer.
				//Process.Start("explorer", null);
			}
		}

	} //-- eof
}